'''
Description: robot description launch file
Version: V1.0
Author: zw_1520@163.com
Date: 2025-07-08 08:13:28
LastEditors: zw_1520@163.com
LastEditTime: 2025-07-17 14:55:58
Copyright (C) 2024-2050 Lens All rights reserved.
'''

import os
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
    package_name = 'robot_description'
    urdf_name = "zr_encos.urdf"

    launch_description = LaunchDescription()
    pkg_share = FindPackageShare(package=package_name).find(package_name)
    urdf_model_path = os.path.join(pkg_share, f'urdf/{urdf_name}')

    robot_state_publisher_node = Node(package='robot_state_publisher',
                                      executable='robot_state_publisher',
                                      arguments=[urdf_model_path])

    joint_state_publisher_node = Node(
        package='joint_state_publisher_gui',
        executable='joint_state_publisher_gui',
        name='joint_state_publisher_gui',
        arguments=[urdf_model_path]
    )

    rviz2_node = Node(
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        output='screen',
    )

    launch_description.add_action(robot_state_publisher_node)
    launch_description.add_action(joint_state_publisher_node)
    launch_description.add_action(rviz2_node)

    return launch_description
